package com.xxxy.dongyexuan.mapper;

import com.xxxy.dongyexuan.po.Flow;
import com.xxxy.dongyexuan.po.Level;
import com.xxxy.dongyexuan.po.Reservation;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;

@MapperScan("com.xxxy.dongyexuan.demobeautyhaird.mapper")
public interface IReservationMapper{
    @Select("select count(*) from reservation")
    public int getcount();

    @Select("SELECT * FROM reservation_log WHERE rid = #{rid}")
    public Reservation findById(@Param("rid") int rid);

    @Select("SELECT * FROM reservation_log WHERE pid = #{rid} and menuname = #{menuname}")
    public List<Reservation> findLogById(@Param("rid") int rid, @Param("menuname") String menuname);

    @Select("SELECT * FROM reservation")
    public List<Reservation> findAll();

    @Insert("INSERT reservation VALUES (#{rid},#{uid},#{uname},#{rtime},#{eid},#{tid},#{state},#{pid},#{way},#{money})")
    public int save(Reservation reservation);

    @Insert("INSERT reservation_log(rid,uid,uname,rtime,eid,tid,pid,money,`state`,way,remark,timerange,menuname,order_id) VALUES (#{rid},#{uid},#{uname},#{rtime},#{eid},#{tid},#{pid},#{money},#{state},#{way},#{remark},#{timerange},#{menuname},#{orderId})")
    @Options(useGeneratedKeys = true, keyProperty = "rid", keyColumn = "rid")
    public int saveLog(Reservation reservation);

    @Update("UPDATE reservation SET uid = #{uid},uname = #{uname},eid = #{eid},tid = #{tid},state = #{state},pid = #{pid},way = #{way},money = #{money} WHERE rid = #{rid}")
    public int merge(Reservation reservation);

    @Delete("DELETE FROM reservation WHERE rid = #{rid}")
    public int delete(@Param("rid") int rid);

    @Delete("DELETE FROM reservation_log WHERE rid = #{rid}")
    public int deleteLog(@Param("rid") int rid);
    @Select("select * from reservation_log where uid = #{uid} limit #{from},#{pagesize}")
    public List<Reservation> findLogByPage(@Param("from") int from, @Param("pagesize") int pagesize, @Param("uid") int uid);

    @Select("select * from reservation_log limit #{from},#{pagesize}")
    public List<Reservation> findAllLogByPage(@Param("from") int from, @Param("pagesize") int pagesize);

    @Select("select * from reservation limit #{from},#{pagesize}")
    public List<Reservation> findByPage(@Param("from") int from, @Param("pagesize") int pagesize);

    @Update("UPDATE reservation_log SET state = 1 WHERE rid = #{rid}")
    public void updateState(@Param("rid") int rid);
}



